﻿@namespace AntDesign
@using Microsoft.AspNetCore.Components.Rendering
@inherits AntDomComponentBase

<CascadingValue Value="this" IsFixed>
    @if (ShowTooltip)
    {
        <Tooltip TitleTemplate="@content" Placement="@Placement.Right" Disabled="TooltipDisabled">
            <Unbound Context="tooltip">
                @MenuItemContent(tooltip)
            </Unbound>
        </Tooltip>
    }
    else
    {
        @MenuItemContent(RefBack);
    }
</CascadingValue>

@code {

    RenderFragment MenuItemContent(ForwardRef refBack)
    {
        return@<li class="@ClassMapper.Class" role="menuitem" style="@PaddingStyle @Style" @onclick="HandleOnClick" @key="Key" @ref="refBack.Current">
            @icon
            <span class="ant-menu-title-content">
                @if (RouterLink == null)
                {
                    @content
                }
                else
                {
                    <MenuLink Href="@RouterLink" Match="@RouterMatch" Target="Target">@content</MenuLink>
                }
            </span>
        </li>;
    }

    void content(RenderTreeBuilder __builder)
    {
        @if (Title != null)
        {
            @Title
        }
        else
        {
            @ChildContent
        }
    }


    void icon(RenderTreeBuilder __builder)
    {
        if (IconTemplate != null)
        {
            <span role="img" class=" anticon anticon-container">
                @IconTemplate
            </span>
        }
        else if (Icon != null)
        {
            <Icon Type="@Icon" />
        }
    }

    void TitleContent(RenderTreeBuilder __builder)
    {
        icon(__builder);
        content(__builder);
    }

    internal RenderFragment GetTitleContent()
    {
        return b => TitleContent(b);
    }
}